/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.account;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.account.SysRolePermit;
import com.unis.service.account.SysRolePermitService;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2012-12-11
 */
@Controller
@RequestMapping("/sysrolepermit")
public class SysRolePermitController {

    private SysRolePermitService sysrolepermitService;

    /****************************************
     * Insert a instace of SysRolePermit
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertSysRolePermit(@RequestBody List<?> sysrolepermitList) throws Exception {
        String status = "failure";
        sysrolepermitService.batchInsert(sysrolepermitList);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of SysRolePermit
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody SysRolePermit sysrolepermit) throws Exception {
        sysrolepermit.setStatmentId("SysRolePermit.update");
        String status = "failure";
        sysrolepermitService.update(sysrolepermit);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of SysRolePermit
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody SysRolePermit sysrolepermit) throws Exception {
        sysrolepermit.setStatmentId("SysRolePermit.delete");
        String status = "failure";
        sysrolepermitService.batchDelete(sysrolepermit);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of SysRolePermit
     ****************************************/
    @RequestMapping("/queryAsList/{type}")
    @ResponseBody
    public Object queryAsList(@PathVariable String type, HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        paramMap.put("type", type);
        SysRolePermit sysrolepermit = new SysRolePermit();
        sysrolepermit.setStatmentId("SysRolePermit.queryAsList");
        BeanUtils.populate(sysrolepermit, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(sysrolepermit, pageMap);
        List<BaseModel> sysrolepermitList = sysrolepermitService.queryAsList(sysrolepermit);
        Map<String, Object> renderMap = GridUIMapper.render(sysrolepermit, sysrolepermitList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of SysRolePermit
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody SysRolePermit sysrolepermit) throws Exception {
        sysrolepermit.setStatmentId("SysRolePermit.queryAsObject");
        return sysrolepermitService.queryAsObject(sysrolepermit);
    }

    @RequestMapping("/rolePermitMgr")
    public String rolePermitMgr() {
        return "sys/sysrolepermitList";
    }

    @Resource
    public void setSysRolePermitService(SysRolePermitService sysrolepermitService) {
        this.sysrolepermitService = sysrolepermitService;
    }
}
